/**
 * Bestpay.com.cn Inc.
 * Copyright (c) 2011-2020 All Rights Reserved.
 */
package com.suxiaoxiao.springbootlearn.designpattern.statepattern.goodcode.stateimpl;

import com.suxiaoxiao.springbootlearn.designpattern.statepattern.goodcode.State;
import com.suxiaoxiao.springbootlearn.designpattern.statepattern.goodcode.pojo.GumballMachine;

/**
 * 售出糖果
 *
 * @author zhaorongzhang
 * @version SoldState.java, v 0.1 2020/1/9 9:30 下午 zhaorongzhang Exp $$
 */
public class SoldState extends State {

    transient GumballMachine gumballMachine;

    public SoldState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void dispense() {
        gumballMachine.releaseBall();
        if (gumballMachine.getCount() > 0) {
            gumballMachine.setState(gumballMachine.getNoQuarterState());
        } else {
            System.out.println("售尽啦");
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }
    }

}